import requests
from py02_tpshop_api import TpshopApi


class TestApiLogin(object):
    def setup_class(self):
        self.tpshop = TpshopApi()

    def setup(self):
        self.session = requests.Session()
        self.tpshop.get_verify_code(self.session)

    def test01_login_success(self):
        req_body = {"username": "13012345678", "password": "123456", "verify_code": "8888"}
        resp = self.tpshop.login(self.session, req_body)
        print("登录成功", resp)

        assert 200 == resp.status_code
        assert 1 == resp.json().get("status")
        assert "成功" in resp.json().get("msg")

    def test02_pwd_err(self):
        req_body = {"username": "13012345678", "password": "123456789", "verify_code": "8888"}
        resp = self.tpshop.login(self.session, req_body)
        print("密码错误", resp)

        assert 200 == resp.status_code
        assert -2 == resp.json().get("status")
        assert "错误" in resp.json().get("msg")

    def test03_verify_code_err(self):
        req_body = {"username": "13012345678", "password": "123456", "verify_code": "8899"}
        resp = self.tpshop.login(self.session, req_body)
        print("验证码错误", resp)

        assert 200 == resp.status_code
        assert 0 == resp.json().get("status")
        assert "错误" in resp.json().get("msg")





















